package com.lifeng.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Created by lifeng on 2019/7/31.
 * 设置跨域
 */
@Configuration
public class CorsConfig implements WebMvcConfigurer {

    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*") //1允许任何域名使用
                .allowCredentials(true)
                .allowedHeaders("*") //2允许任何头
                .allowedMethods("GET", "POST", "DELETE", "PUT") //允许的方法
                .maxAge(3600);
    }
}